package sddz.foodmanage.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;
import android.widget.ImageView;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.ButterKnife;
import sddz.foodmanage.R;
import sddz.foodmanage.base.BaseActivity;
import sddz.foodmanage.utils.SpfUtils;
//import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2017/3/23.
 */

public class WelcomeActivity extends BaseActivity {
    private ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        initView();
    }

    private void initView() {
        image = (ImageView) findViewById(R.id.image);
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                boolean login = SpfUtils.isLogin(mActivity);
               String token= SpfUtils.gettoken(mActivity);
                if (login&&!TextUtils.isEmpty(token)) {
                    startActivity(new Intent(mActivity, MainNewActivity.class));
                } else {
                    //去登录页
                    startActivity(new Intent(mActivity, LoginActivity.class));
                }
                finish();
            }
        };
        timer.schedule(task, 1000 * 2); //2秒后
        //极光，往后台发送id
//        String registrationId = JPushInterface.getRegistrationID(this);
//        Log.e("1099", "run:--------->registrationId： "+registrationId );
//        Map<String, String> params = new HashMap<>();
//        params.put("registrationId", registrationId);
//        params.put("content", "登录成功");
//        OkHttpUtils.getInstance().POST(mActivity, params, API.getJGregistrationId, new OkHttpUtils.OnOkHttpCallback() {
//            @Override
//            public void onSuccess(String body) {
//                Log.e("body",body);
//                try {
//                    JSONObject object = new JSONObject(body);
//                    if(object.optInt("code")==0){
//                        Log.e("msg",object.optString("msg"));
//                    }
//
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public void onError(Exception e) {
//
//            }
//        });

    }

}
